package com.cloud.manager.core.result;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * 描述：
 *
 * @author FineEx   2021/11/18
 * @version 1.0
 */
@ApiModel(value = "通用接口返回", description = "Common Api Response")
public class Result<T> {
    /**
     * 通用返回状态
     */
    @ApiModelProperty(value = "通用返回状态Code", required = true)
    private int code;
    /**
     * 通用返回信息
     */
    @ApiModelProperty(value = "通用返回信息", required = true)
    private String message;
    /**
     * 通用返回数据
     */
    @ApiModelProperty(value = "通用返回数据", required = true)
    private T data;

    public Result() {
    }

    private Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public Result<T> setCode(int code) {
        this.code = code;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public Result<T> setMessage(String message) {
        this.message = message;
        return this;
    }

    public T getData() {
        return data;
    }

    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }

    /**
     * 返回值code
     */
    public enum Code {
        // 成功
        SUCCESS(200),

        // 失败
        FAIL(400),

        // 未认证（签名错误）
        UNAUTHORIZED(401),

        // 接口不存在
        NOT_FOUND(404),

        /**
         * 未登录
         */
        UNAUTHEN(4401),

        /**
         * 未授权，拒绝访问
         */
        UNAUTHZ(403),

        // 服务器内部错误
        INTERNAL_SERVER_ERROR(500);

        public int code;

        Code(int code) {
            this.code = code;
        }
    }
}
